
const app = getApp()
Page({
  data: {
    dealId:0,
    result:[],
    marketList:[],
    userInfo:{}
  },
  onLoad: function (options) {
    this.setData({
      dealId:options.id
    })
    this.getMallList(options.id)
  },
  getMallList(id){
    let _this = this
    app.util.request({
      url: "api/deal/findAllById",
      method: "post",
      data: {
        id:id
      },
      success(response) {
        if (response.data.code == 0) {
          _this.setData({
            marketList: response.data.data.jsonArray,
            userInfo: response.data.data.account
          })
        }
      }
    })
  },
  onChange(event) {
    this.setData({
      result: event.detail
    });
  },

  toggle(event) {
    let id = event.currentTarget.dataset.item.mall.id
    let arr = [String(id)]
    this.setData({
      result: arr
    })
    return
    const { index } = event.currentTarget.dataset;
    const checkbox = this.selectComponent(`.checkboxes-${index}`);
    checkbox.toggle();
  },
  toChange(){
    let _this = this
    app.util.request({
      url: "api/orders/deal",
      method: "post",
      data: {
        mallId:this.data.result[0],
        dealId: _this.data.dealId
      },
      success(response) {
        if (response.data.code == 0) {
         wx.navigateTo({
           url: '/pages/goods/my-goods-index',
         })
        }else{
          wx.showToast({
            icon:'none',
            title:response.data.msg
          })
        }
      }
    })
  },
})
